#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class SVNRepo:
    @classmethod
    def isBadVersion(cls, id):
        if id >= 1:
            return True
        else:
            return False

class Solution:
    """
    @param n: An integer
    @return: An integer which is the first bad version.
    """
    def findFirstBadVersion(self, n):
        # assert SVNRepo.isBadVersion(n)            # assert 会导致isBadVersion调用超过次数
        if SVNRepo.isBadVersion(1):
            return 1

        good = 1
        bad = n

        while good < bad-1:
            mid = (good + bad) // 2
            if SVNRepo.isBadVersion(mid):
                bad = mid
            else:
                good = mid

        return good + 1


def main():
    print("start main")
    s = Solution()
    ret = s.findFirstBadVersion(1)
    print(ret)

if __name__ == "__main__":
    main()
